﻿@{
    ViewBag.Title = "样品定义";
}

<div class="row col-md-12 ml-0" style="min-height:5vh;">
    <strong class="font-rfs" style="margin-right: 2rem;padding-top: 0.4rem;">样品定义</strong>
    <select id="SampleDefinition-Select-Site" class="form-control font-rfs border-radius-noleft custom-headtoolbar-select" style="width: 8%;"></select>
    <select id="SampleDefinition-Select-Classification" class="form-control font-rfs custom-headtoolbar-select" style="width: 8%;"></select>
    <select id="SampleDefinition-Select-GenricClass" class="form-control font-rfs custom-headtoolbar-select" style="width: 8%;"></select>
    <button id="SampleDefinition-AddSampleDefinition" class="btn btn-rfs"><i class="bi-plus-square"></i> 添加</button>
    <button id="SampleDefinition-EditSampleDefinition" class="btn btn-rfs"><i class="bi-pencil-square"></i> 编辑</button>
    <button id="SampleDefinition-DelSampleDefinition" class="btn btn-rfs"><i class="bi-trash"></i> 删除</button>
    <button id="SampleDefinition-CopySampleDefinition" class="btn btn-rfs" Title="复制样品"><i class="bi-files" style="color: #007bff;"></i> 复制</button>
    <button id="SampleDefinition-SetSkipWorkflow" class="btn btn-rfs"><i class="bi-gear"></i> 流程配置</button>
    <input id="SampleDefinition-Name" class="btn btn-rfs" style="border: 1px solid rgba(0,0,0,.15);" onchange="SearchName(this)" placeholder="按样品名称模糊搜索" />
</div>
<div class="row col-md-12 ml-0 pre-scrollable" style="min-height:90vh;">
    <div class="row col-md-12" style="padding-right:0px;left: 15px;padding-left: 0px;min-height:40vh;">
        <div class="table-responsive-sm shadow p-0 bg-white rounded col-md-12 pre-scrollable" style="min-height:40vh;">
            <table id="SampleDefinition-Table" class="table table-striped table-bordered table-sm table-hover">
                <thead>
                    <tr>
                        <th>ID</th>
                        <th>名称</th>
                        <th>默认编号</th>
                        <th>描述</th>
                        <th>实验室</th>
                        <th>工作组</th>
                        <th>流程</th>
                        <th>报告</th>
                        <th>采样点</th>
                        <th>发布</th>
                        <th>留样</th>
                        <th>留样配置</th>
                    </tr>
                </thead>
                <tbody></tbody>
            </table>
        </div>
    </div>
    <div class="row col-md-12 ml-0" style="margin-top: 8px; padding-right:0px;padding-left: 0px;min-height:49vh;">
        <div class="row col-md-12 tab-content" style="padding-left: 0;padding-right: 0px;right: -15px;height: 3vh;">
            <ul class="nav col-md-12" style="padding-right: 0;margin-bottom: 1px;">
                <li id="li-tabAnalyte" class="tabButton col-md-1 tab-first-active font-rfs" style="text-align:center;padding-left: 1px;padding-right: 1px;" data-active="true">
                    <a id="a-tabAnalyte" href="#tabAnalyte" data-toggle="tab" class="text-decoration-none" style="display: inline-block;width:100%;">分析项</a>
                </li>
                <li id="li-tabTestDefinition" class="tabButton col-md-1 tab-other-noactive font-rfs" style="text-align: center;padding-left: 1px;padding-right: 1px;" data-active="false">
                    <a id="a-tabTestDefinition" href="#tabTestDefinition" data-toggle="tab" class="text-decoration-none" style="display: inline-block;width:100%;">测试</a>
                </li>
                <li id="li-tabSpecCollection" class="tabButton col-md-1 tab-other-noactive font-rfs" style="text-align: center;padding-left: 1px;padding-right: 1px;" data-active="false">
                    <a id="a-tabSpecCollection" href="#tabSpecCollection" data-toggle="tab" class="text-decoration-none" style="display: inline-block;width:100%;">指标集</a>
                </li>
                <li class="col-md-9 tab-Notactive" style="text-align: center;"><a href="" data-toggle="tab"></a></li>
            </ul>
        </div>
        <div class="row col-md-12 tab-content tab-body" style="padding-right: 0px;right: -15px;padding-left: 0px;top: -2px;min-height:46vh;">
            <div class="col-md-12 ml-0 mr-0 tab-pane active" id="tabAnalyte" style="padding-left: 0px;padding-right: 0px;">
                <div class="row col-md-12" style="min-height:2vh;">
                    <button id="SampleDefinition-tabAnalyte-addAnalyte" class="btn btn-rfs"><i class="bi-plus-square"></i> 添加</button>
                    <button id="SampleDefinition-tabAnalyte-delAnalyte" class="btn btn-rfs"><i class="bi-trash" onclick=""></i> 删除</button>
                </div>
                <div class="table-responsive-sm p-0 bg-white rounded col-md-12 pre-scrollable" style="min-height:30vh;">
                    <table id="SampleDefinition-tab-Analyte" class="table table-striped table-bordered table-sm table-hover">
                        <thead>
                            <tr>
                                <th>ID</th>
                                <th>代码</th>
                                <th>名称</th>
                                <th>分类</th>
                                <th>描述</th>
                                <th>结果模式</th>
                                <th>修约</th>
                                <th>单位</th>
                                <th>默认指标名</th>
                                <th>检测次数</th>
                                <th>报告过滤</th>
                            </tr>
                        </thead>
                        <tbody></tbody>
                    </table>
                </div>
            </div>
            <div class="col-md-12 ml-0 mr-0 tab-pane" id="tabTestDefinition" style="padding-left: 0px;padding-right: 0px;">
                <div class="row col-md-6 float-md-left" style="min-height:2vh;">
                    <div class="row col-md-12" style="min-height:2vh;">
                        <button id="SampleDefinition-tabTestDefinition-addTD" class="btn btn-rfs"><i class="bi-plus-square"></i> 添加</button>
                        <button id="SampleDefinition-tabTestDefinition-delTD" class="btn btn-rfs"><i class="bi-trash" onclick=""></i> 删除测试</button>
                    </div>
                    <div class="table-responsive-sm shadow p-0 bg-white rounded col-md-12 float-md-left pre-scrollable" style="min-height:41vh;">
                        <table id="SampleDefinition-tabTestDefinition-TD" class="table table-striped table-bordered table-sm table-hover">
                            <thead>
                                <tr>
                                    <th>ID</th>
                                    <th>测试名称</th>
                                    <th>描述</th>
                                    <th>一级分类</th>
                                    <th>二级分类</th>
                                    <th>检测次数</th>
                                    <th>版本</th>
                                </tr>
                            </thead>
                            <tbody></tbody>
                        </table>
                    </div>
                </div>
                <div class="col-md-12 ml-0 mr-0 tab-pane" style="padding-left: 0px;padding-right: 0px;">
                    <div class="row col-md-6 float-md-left" style="margin-left: 0px;margin-top: 11px;padding-right: 0px;">
                        <div class="row col-md-12" style="padding-right: 0px;margin-right: 0px;right: -15px;padding-left: 0px;min-height:2vh;">
                            <ul class="nav col-md-12" style="padding-right: 0;margin-bottom: 1px;">
                                <li id="li-tabTestSpecCollection" class="tabButton col-md-1 tab-first-active font-rfs" style="text-align:center;padding-left: 1px;padding-right: 1px;" data-active="true">
                                    <a id="a-tabTestSpecCollection" href="#tabTestSpecCollection" data-toggle="tab" class="text-decoration-none" style="display: inline-block;width:100%;">指标集</a>
                                </li>
                                <li id="li-tabTestMethod" class="tabButton col-md-1 tab-other-noactive font-rfs" style="text-align: center;padding-left: 1px;padding-right: 1px;" data-active="false">
                                    <a id="a-tabTestMethod" href="#tabTestMethod" data-toggle="tab" class="text-decoration-none" style="display: inline-block;width:100%;">方法</a>
                                </li>
                                <li class="col-md-10 tab-Notactive" style="text-align: center;"><a href="" data-toggle="tab"></a></li>
                            </ul>
                        </div>
                        <div class="row col-md-12 tab-content tab-body" style="padding-right: 0px;right: -15px;padding-left: 0px;top: -2px;min-height:30vh;">
                            <div class="col-md-12 ml-0 mr-0 tab-pane active" id="tabTestSpecCollection" style="padding-left: 0px;padding-right: 0px;">
                                <div class="table-responsive-sm shadow p-0 bg-white rounded col-md-12 float-md-left pre-scrollable" style="margin-top: 2px;min-height:41vh;">
                                    <table id="tableTestSpecCollection" class="table table-striped table-bordered table-sm table-hover">
                                        <thead>
                                            <tr>
                                                <th>ID</th>
                                                <th>默认</th>
                                                <th>代码</th>
                                                <th>名称</th>
                                                <th>描述</th>
                                                <th>一级分类</th>
                                                <th>二级分类</th>
                                                <th>版本</th>
                                                <th>状态</th>
                                            </tr>
                                        </thead>
                                        <tbody></tbody>
                                    </table>
                                </div>
                            </div>
                            <div class="col-md-12 ml-0 mr-0 tab-pane" id="tabTestMethod" style="padding-left: 0px;padding-right: 0px;">
                                <div class="table-responsive-sm shadow p-0 bg-white rounded col-md-12 float-md-left pre-scrollable" style="margin-top: 2px;min-height:41vh;">
                                    <table id="tableTestMethod" class="table table-striped table-bordered table-sm table-hover">
                                        <thead>
                                            <tr>
                                                <th>ID</th>
                                                <th>默认</th>
                                                <th>代码</th>
                                                <th>名称</th>
                                                <th>类型</th>
                                                <th>描述</th>
                                                <th>生效日期</th>
                                                <th>有效期至</th>
                                                <th>记录单</th>
                                                <th>版本</th>
                                                <th>状态</th>
                                            </tr>
                                        </thead>
                                        <tbody></tbody>
                                    </table>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="col-md-12 ml-0 mr-0 tab-pane " id="tabSpecCollection" style="padding-left: 0px;padding-right: 0px;">
                <div class="row col-md-12" style="min-height:2vh;">
                    <button id="SampleDefinition-tabSpecCollection-addSpc" class="btn btn-rfs"><i class="bi-plus-square"></i> 添加</button>
                    <button id="SampleDefinition-tabSpecCollection-delSpc" class="btn btn-rfs"><i class="bi-trash" onclick=""></i> 删除</button>
                </div>
                <div class="col-md-12 ml-0 mr-0 tab-pane" style="padding-left: 0px;padding-right: 0px;">
                    <div class="table-responsive-sm shadow p-0 bg-white rounded col-md-12 float-md-left pre-scrollable" style="min-height:41vh;">
                        <table id="SampleDefinition-tabSpecList" class="table table-striped table-sm table-hover">
                            <thead>
                                <tr>
                                    <th>ID</th>
                                    <th>默认</th>
                                    <th>代码</th>
                                    <th>名称</th>
                                    <th>描述</th>
                                    <th>一级分类</th>
                                    <th>二级分类</th>
                                    <th>版本</th>
                                    <th>状态</th>
                                </tr>
                            </thead>
                            <tbody></tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<div class="modal" id="SAMPLE-SampleDefinition-Modal" role="dialog" aria-hidden="true" data-backdrop="static">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class='modal-header'>
                <p id="modalTitle" class="pt-3 pl-3 font-rfs"></p>
                <a data-dismiss="modal" class="modal-close">&times;</a>
            </div>
            <div class="modal-body">
                <div id="Embed"></div>
            </div>
        </div>
    </div>
</div>
<div class="modal" id="SAMPLE-SampleDefinition-DeleteConfirm" role="dialog">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class='modal-header'>
                <p class="pt-3 pl-3 font-rfs">删除</p>
                <a data-dismiss="modal" class="modal-close">&times;</a>
            </div>
            <div class="modal-body">
                <p class="font-rfs">确认删除当前选中样品吗？</p>
            </div>
            <div class="modal-Delete-footer">
                <button id="modal-delete" class="btn btn-outline-primary border-radius-noradius noLeftBorder noRightBorder font-rfs" style="width:50%; height:fit-content">删除</button>
                <button id="modal-cancel" data-dismiss="modal" class="btn btn-outline-primary border-radius-noradius noRightBorder font-rfs" style="width:50%; height:fit-content">取消</button>
            </div>
        </div>
    </div>
</div>
<div class="modal" id="SampleDefinition-DelAnalyteRelation-modal" role="dialog">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class='modal-header'>
                <p class="pt-3 pl-3 font-rfs">删除</p>
                <a data-dismiss="modal" class="modal-close">&times;</a>
            </div>
            <div class="modal-body">
                <p class="font-rfs">确认删除当前分析项吗？</p>
            </div>
            <div class="modal-Delete-footer">
                <button id="SampleDefinition-DelAnalyteRelation-modal-delete" class="btn btn-outline-primary border-radius-noradius noLeftBorder noRightBorder font-rfs" style="width:50%; height:fit-content">删除</button>
                <button id="SampleDefinition-DelAnalyteRelation-modal-cancel" data-dismiss="modal" class="btn btn-outline-primary border-radius-noradius noRightBorder font-rfs" style="width:50%; height:fit-content">取消</button>
            </div>
        </div>
    </div>
</div>
<div class="modal" id="SampleDefinition-DelTestDefinitionRelation-modal" role="dialog">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class='modal-header'>
                <p class="pt-3 pl-3 font-rfs">删除</p>
                <a data-dismiss="modal" class="modal-close">&times;</a>
            </div>
            <div class="modal-body">
                <p class="font-rfs">确认删除当前测试项吗？</p>
            </div>
            <div class="modal-Delete-footer">
                <button id="SampleDefinition-DelTestDefinitionRelation-modal-delete" class="btn btn-outline-primary border-radius-noradius noLeftBorder noRightBorder font-rfs" style="width:50%; height:fit-content">删除</button>
                <button id="SampleDefinition-DelTestDefinitionRelation-modal-cancel" data-dismiss="modal" class="btn btn-outline-primary border-radius-noradius noRightBorder font-rfs" style="width:50%; height:fit-content">取消</button>
            </div>
        </div>
    </div>
</div>
<div class="modal" id="SampleDefinition-DelSpecCollectionRelation-modal" role="dialog">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class='modal-header'>
                <p class="pt-3 pl-3 font-rfs">删除</p>
                <a data-dismiss="modal" class="modal-close">&times;</a>
            </div>
            <div class="modal-body">
                <p class="font-rfs">确认删除当前指标集吗？</p>
            </div>
            <div class="modal-Delete-footer">
                <button id="SampleDefinition-DelSpecCollectionRelation-modal-delete" class="btn btn-outline-primary border-radius-noradius noLeftBorder noRightBorder font-rfs" style="width:50%; height:fit-content">删除</button>
                <button id="SampleDefinition-DelSpecCollectionRelation-modal-cancel" data-dismiss="modal" class="btn btn-outline-primary border-radius-noradius noRightBorder font-rfs" style="width:50%; height:fit-content">取消</button>
            </div>
        </div>
    </div>
</div>
<div class="modal" id="SampleDefinition-Modal-RetentionConfig" role="dialog">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class='modal-header'>
                <p class="pt-3 pl-3 font-rfs">选择留样配置</p>
                <a data-dismiss="modal" class="modal-close">&times;</a>
            </div>
            <div class="modal-body">
                <div class="input-group">
                    <div class="col-3 pr-0">
                        <span class="input-group-text font-rfs border-radius-noright noRightBorder">当前配置</span>
                    </div>
                    <div class="col-9 pl-0">
                        <select id="Modal-Select-CRetentionConfig" class="form-control font-rfs border-radius-noleft"></select>
                    </div>
                </div>
                <div class="input-group">
                    <div class="col-3 pr-0">
                        <span class="input-group-text font-rfs border-radius-noright noRightBorder">选择配置</span>
                    </div>
                    <div class="col-9 pl-0">
                        <select id="Modal-Select-SRetentionConfig" class="form-control font-rfs border-radius-noleft"></select>
                    </div>
                </div>
            </div>
            <div class="modal-Delete-footer">
                <button id="SampleDefinition-Modal-RetentionConfig-confirm" class="btn btn-outline-primary border-radius-noradius noLeftBorder noRightBorder font-rfs" style="width:50%; height:fit-content">确定</button>
                <button id="SampleDefinition-Modal-RetentionConfig-cancel" data-dismiss="modal" class="btn btn-outline-primary border-radius-noradius noRightBorder font-rfs" style="width:50%; height:fit-content">取消</button>
            </div>
        </div>
    </div>
</div>

@section Scripts {
    <script>
        var SampleDefinition_Id = "";
        var SampleDefinition_AnalyteId = "";
        var SampleDefinition_TestDefinitonId = "";
        var TestDefinition_SpecCollectionId = "";
        var SampleDefinition_SpecCollectionId= "";

        $(document).ready(function () {
            LoadSite();
            LoadSampleDefinitionClassification();
        });

        /*加载 样品类型 信息*/
        function LoadSampleDefinitionClassification() {
            $.post("GetSampleDefinitionClassification", {
                //Type: type  // 传递的参数，对应控制器里的参数
            }, function (data) {
                for (var i = 0; i < data.length; i++) {
                    $("#SampleDefinition-Select-Classification").append(new Option(data[i].classification));
                }
                $("#SampleDefinition-Select-Classification").prepend(new Option("全部"));
                $("#SampleDefinition-Select-Classification").prepend(new Option("", ""));
                $("#SampleDefinition-Select-Classification").val("");
            });
        }

        //加载实验室列表
        function LoadSite() {
            $.post("GetSiteList", {
                //Type: type  // 传递的参数，对应控制器里的参数
            }, function (data) {
                for (var i = 0; i < data.length; i++) {
                    $("#SampleDefinition-Select-Site").append(new Option(data[i]));
                }
                $("#SampleDefinition-Select-Site").prepend(new Option("", ""));
                $("#SampleDefinition-Select-Site").val("");
            });
        }

        $("#SampleDefinition-Select-Classification").change(function () {
            $.post("GetSampleDefinitionGenricClass", {
                Site:$("#SampleDefinition-Select-Site").find("option:selected").text(),
                Classification: $("#SampleDefinition-Select-Classification").find("option:selected").text()
            }, function (data) {
                $("#SampleDefinition-Select-GenricClass").empty();
                for (var i = 0; i < data.length; i++) {
                    $("#SampleDefinition-Select-GenricClass").append(new Option(data[i].genricClass));
                }
                $("#SampleDefinition-Select-GenricClass").prepend(new Option("", ""));
                $("#SampleDefinition-Select-GenricClass").val("");

                RefreshSampleDefinitionTable();
            });
        });

        $("#SampleDefinition-Select-GenricClass").change(function () {
            RefreshSampleDefinitionTable();
        });

        function RefreshSampleDefinitionTable() {
            SampleDefinition_Id = "";  /*清空该值*/
            $('#SampleDefinition-Table').bootstrapTable('destroy'); // 这行代码必须加，否则数据无法刷新
            var columns = [{ field: "id", visible: false }, { field: "name" }, { field: "defaultNumber" }, { field: "description" }, { field: "site" },
            { field: "group" }, { field: "workFlowName" }, { field: "reportName" }, { field: "samplingPoint" },
            { field: "isRelease", width: "5%", align: "center", formatter: SetRelease },{ field: "isRetention", width: "5%", align: "center", formatter: SetRetention },
            { field: "retentionUnit", width: "10%", formatter: SetRetentionConfig }];

            $('#SampleDefinition-Table').bootstrapTable({
                method: 'post',
                url: "GetSampleDefinitionListClassAndGenric",
                dataType: "json",  // 服务器端返回值类型
                contentType: "application/x-www-form-urlencoded; charset=UTF-8", // 如果是 POST 请求，这个属性必须加
                queryParams: function (params) {
                    var data = {
                        limit:params.limit, // 每页显示多少条记录
                        offset:params.offset, // 偏移量

                        Site:$("#SampleDefinition-Select-Site").find("option:selected").text(),
                        Classification: $("#SampleDefinition-Select-Classification").find("option:selected").text(),  // 传递的参数，这的名称要和控制器里对应的参数名称一样
                        GenricClass: $("#SampleDefinition-Select-GenricClass").find("option:selected").text()
                    };
                    return data;
                }, //参数
                queryParamsType: "limit", // 服务器端分页，这个参数必需是“limit”
                dataField:"rows",

                uniqueId: "id",          // 设置主键
                //search: true,  // 显示查询工具栏
                //showRefresh: true,  // 显示刷新按钮
                //showColumns: true,  // 可控制列的隐藏和显示
                sidePagination: "server", // 服务器端分页，这个参数必需设置
                pagination: true,  // 显示分页条,设为true，启用了分页功能
                pageNumber: 1,
                pageSize: 10,   // 默认页大小
                pageList: [5, 10, 15, 20],  // 控制每页数目
                //showToggle: true,  //
                locale: "zh-CN",
                columns: columns,          // 加载列定义, 注意！这个地方绑定的列名称开头大写字母会全部变成小写。
                onClickRow: function (row, $element, field) {
                    if (row.id != SampleDefinition_Id) {
                        $("#SampleDefinition-Table").find("tbody").find("tr").each(function () {
                            $(this).removeClass('changeblueColor');
                        });
                        $element.addClass("changeblueColor");
                        SampleDefinition_Id = row.id;
                        LoadAnalyte(SampleDefinition_Id);
                        LoadTestDefinition();
                        LoadSpecCollection(SampleDefinition_Id);
                        $('#tableTestMethod').bootstrapTable('destroy');
                        $('#tableTestSpecCollection').bootstrapTable('destroy');
                    }
                },
                silent: true,  //刷新事件必须设置
                formatLoadingMessage: function () {
                    return "请稍等，正在加载中...";
                },
                formatNoMatches: function () {  //没有匹配的结果
                    return '无符合条件的记录';
                },
                onLoadError: function (data) {
                    $('#SampleDefinition-Table').bootstrapTable('removeAll');
                },
                onLoadSuccess: function (data) {   // 数据加载成功后触发该事件
                    SetBootstrapStyle();
                },
                formatShowingRows: function (pageFrom, pageTo, totalRows) {
                    return "正在显示第" + pageFrom + "到第" + pageTo + "条记录，总共" + totalRows + "条记录 ";
                },
                formatRecordsPerPage: function (pageNumber) {
                    return " 每页显示" + pageNumber + '条记录';
                }
            });
        }

        function UpdateRetentionTime(obj) {
            var st = $(obj).val();
            var id = $(obj).parent().parent().attr('data-uniqueid');  // 获得单元格所在行的 ID
            $.post("UpdateSampleDefenitionRetentionTime", {
                SampleDefefinitionId: id,
                RetentionTime: st
            }, function (data) {
                if (data.indexOf("成功") < 0) {
                    alert(data);
                }
            });
        }

        function UpdateRemind(obj) {
            var st = $(obj).val();
            var id = $(obj).parent().parent().attr('data-uniqueid');  // 获得单元格所在行的 ID
            $.post("UpdateSampleDefenitionRemind", {
                SampleDefefinitionId: id,
                Remind: st
            }, function (data) {
                if (data.indexOf("成功") < 0) {
                    alert(data);
                }
            });
        }

        function SetRetentionConfig(value, row, index) {
            var strHtml = "<button class='table-cell-button btn-rfs' data-retentionConfigid=" + row.retentionConfigId + " onclick='RetentionConfigButton(this)'><i class='bi-tools'></i></button>";
            return strHtml;
        }

        function RetentionConfigButton(obj) {
            $("#SampleDefinition-Modal-RetentionConfig").modal({
                backdrop: 'static',
                keyboard: false
            });

            var retentionConfigId = $(obj).attr("data-retentionConfigid");
            $.post("GetRetentionConfigName", {
            }, function (datas) {
                $("#Modal-Select-CRetentionConfig").empty();
                $("#Modal-Select-SRetentionConfig").empty();
                for (var i = 0; i < datas.length; i++) {
                    $("#Modal-Select-CRetentionConfig").append(new Option(datas[i].name, datas[i].id));
                }
                $("#Modal-Select-CRetentionConfig").prepend(new Option("", ""));
                $("#Modal-Select-CRetentionConfig").val(retentionConfigId);
                $("#Modal-Select-CRetentionConfig").attr("disabled", true);

                for (var i = 0; i < datas.length; i++) {
                    $("#Modal-Select-SRetentionConfig").append(new Option(datas[i].name, datas[i].id));
                }
            });
        }

        function SetRelease(value, row, index) {
            var strHtml = "";
            if (row.isRelease) {
                strHtml = "<input type='checkbox' checked onclick='ReleaseOnClick(this)' data-rowid='" + row.id + "'/>";
            } else {
                strHtml = "<input type='checkbox' onclick='ReleaseOnClick(this)' data-rowid='" + row.id + "'/>";
            }
            return strHtml;
        }

        function ReleaseOnClick(obj) {
            var st = $(obj).prop("checked");
            var rowid = $(obj).attr("data-rowid");

            $.post("UpdateSampleDefenitionIsRelease", {
                SampleDefefinitionId: rowid,
                IsRelease: st
            }, function (data) {
                if (data.indexOf("成功") < 0) {
                    alert(data);
                }
            });
        }

        function SetRetention(value, row, index) {
            var strHtml = "";
            if (row.isRetention) {
                strHtml = "<input type='checkbox' checked onclick='RetentionOnClick(this)' data-rowid='" + row.id + "'/>";
            } else {
                strHtml = "<input type='checkbox' onclick='RetentionOnClick(this)' data-rowid='" + row.id + "'/>";
            }
            return strHtml;
        }

        function RetentionOnClick(obj) {
            var st = $(obj).prop("checked");
            var rowid = $(obj).attr("data-rowid");

            $.post("UpdateSampleDefenitionIsRetention", {
                SampleDefefinitionId: rowid,
                IsRetention: st
            }, function (data) {
                if (data.indexOf("成功") < 0) {
                    alert(data);
                }
            });
        }

        function LoadAnalyte(SampleDefinition_Id) { 
            SampleDefinition_AnalyteId = "";
            var columns = [{ field: "id", visible: false }, { field: "code" }, { field: "name" }, { field: "classification" }, { field: "description"},
            { field: "resultModel" }, { field: "roundingOff" }, { field: "units" }, { field: "defaultSpecName" }, { field: "repeat", width: "5%", formatter: SetRepeat },
            { field: "assist" }];

            $('#SampleDefinition-tab-Analyte').bootstrapTable('destroy'); // 这行代码必须加，否则数据无法刷新
            $('#SampleDefinition-tab-Analyte').bootstrapTable({
                method: 'post',
                url: "GetSampleDefinitionRelationAnalytes",
                dataType: "json",  // 服务器端返回值类型
                contentType: "application/x-www-form-urlencoded; charset=UTF-8", // 如果是 POST 请求，这个属性必须加
                queryParams: function (params) {
                    var data = {
                        SampleDefinitonId: SampleDefinition_Id,  // 传递的参数，这的名称要和控制器里对应的参数名称一样
                    };
                    return data;
                }, //参数
                queryParamsType: "search", //参数格式,发送标准的RESTFul类型的参数请求

                uniqueId: "id",
                locale: "zh-CN",
                columns: columns,
                onClickRow: function (row, $element, field) {
                    $("#SampleDefinition-tab-Analyte").find("tbody").find("tr").each(function () {
                        $(this).removeClass('changeblueColor');
                    });
                    $element.addClass("changeblueColor");
                    SampleDefinition_AnalyteId = row.id;
                },
                silent: true,  //刷新事件必须设置
                formatLoadingMessage: function () {
                    return "请稍等，正在加载中...";
                },
                formatNoMatches: function () {  //没有匹配的结果
                    $('.fixed-table-toolbar').css("height", "0px"); /* 隐藏表格上的工具栏 */
                    return '无符合条件的记录';
                },
                onLoadError: function (data) {
                    $('#Analyte').bootstrapTable('removeAll');
                },
                onLoadSuccess: function (data) {   // 数据加载成功后触发该事件
                    SetBootstrapStyle();
                }
            });
        }

        function SearchName(obj) {
            LoadSampleDefinitionByName($(obj).val());
        }

        function LoadSampleDefinitionByName(Name) {
            SampleDefinition_Id = "";  /*清空该值*/
            $('#SampleDefinition-Table').bootstrapTable('destroy'); // 这行代码必须加，否则数据无法刷新
            var columns = [{ field: "id", visible: false }, { field: "name" }, { field: "description" }, { field: "site" },
            { field: "group" }, { field: "workFlowName" }, { field: "reportName" }];

            $('#SampleDefinition-Table').bootstrapTable({
                method: 'post',
                url: "GetSampleDefinitionListByName",
                dataType: "json",  // 服务器端返回值类型
                contentType: "application/x-www-form-urlencoded; charset=UTF-8", // 如果是 POST 请求，这个属性必须加
                queryParams: function (params) {
                    var data = {
                        limit: params.limit, // 每页显示多少条记录
                        offset: params.offset, // 偏移量

                        Name: Name  // 传递的参数，这的名称要和控制器里对应的参数名称一样
                    };
                    return data;
                },
                queryParamsType: "limit", // 服务器端分页，这个参数必需是“limit”
                dataField: "rows",

                uniqueId: "id",          // 设置主键
                sidePagination: "server", // 服务器端分页，这个参数必需设置
                pagination: true,  // 显示分页条,设为true，启用了分页功能
                pageNumber: 1,
                pageSize: 10,   // 默认页大小
                pageList: [5, 10, 15, 20],  // 控制每页数目
                locale: "zh-CN",
                columns: columns,          // 加载列定义, 注意！这个地方绑定的列名称开头大写字母会全部变成小写。
                onClickRow: function (row, $element, field) {
                    $("#SampleDefinition-Table").find("tbody").find("tr").each(function () {
                        $(this).removeClass('changeblueColor');
                    });
                    $element.addClass("changeblueColor");
                    SampleDefinition_Id = row.id;
                    LoadAnalyte(SampleDefinition_Id);
                    LoadTestDefinition();
                    LoadSpecCollection(SampleDefinition_Id);
                },
                silent: true,  //刷新事件必须设置
                formatLoadingMessage: function () {
                    return "请稍等，正在加载中...";
                },
                formatNoMatches: function () {  //没有匹配的结果
                    return '无符合条件的记录';
                },
                onLoadError: function (data) {
                    $('#SampleDefinition-Table').bootstrapTable('removeAll');
                },
                onLoadSuccess: function (data) {   // 数据加载成功后触发该事件
                    SetBootstrapStyle();
                },
                formatShowingRows: function (pageFrom, pageTo, totalRows) {
                    return "正在显示第" + pageFrom + "到第" + pageTo + "条记录，总共" + totalRows + "条记录 ";
                },
                formatRecordsPerPage: function (pageNumber) {
                    return " 每页显示" + pageNumber + '条记录';
                }
            });
        }

        $("#SampleDefinition-DelSampleDefinition").click(function () {
            if (SampleDefinition_Id == "") {
                return false;
            }

            $("#SAMPLE-SampleDefinition-DeleteConfirm").modal({
                backdrop: 'static',
                keyboard: false
            });
        });

        $("#SampleDefinition-CopySampleDefinition").click(function () {
            if (SampleDefinition_Id.length == 0) {
                return;
            }
            $.post("CopySampleDefinition", {
                Id: SampleDefinition_Id
            }, function (data) {
                alert(data);
            });
        });

        $("#SampleDefinition-SetSkipWorkflow").click(function () {
            if (SampleDefinition_Id == "") {
                return false;
            }

            $("#modalTitle").text("流程配置");

            $("#SAMPLE-SampleDefinition-Modal").modal({
                backdrop: 'static',
                keyboard: false
            });

            $.post("SetSkipWorkflow", {
                SampleDefefinitionId: SampleDefinition_Id,
                ModalID: "SAMPLE-SampleDefinition-Modal"
            }, function (datas) {
                $("#Embed").html(datas);
            });
        });

        $("#modal-delete").click(function () {
            $.post("postDeleteSampleDefinition", {
                Id: SampleDefinition_Id
            }, function (data) {
                if (data.indexOf("成功") >= 0) {
                    $('#SampleDefinition-Table').bootstrapTable('removeByUniqueId', SampleDefinition_Id);  // 删除指定的行
                    SampleDefinition_Id = "";  // 删除行后，将这个值置空，否则直接编辑信息就会报错。
                    $('#SampleDefinition-tab-Analyte').bootstrapTable('removeAll');
                } else {
                    alert(data);
                }
            });

            $("#SAMPLE-SampleDefinition-DeleteConfirm").modal('hide');
        });

        $("#SampleDefinition-DelAnalyteRelation-modal-delete").click(function () {
            $.post("DelteRelationSDAndAanylte", {
                RelationId: SampleDefinition_AnalyteId
            }, function (data) {
                if (data.indexOf("成功") >= 0) {
                    $('#SampleDefinition-tab-Analyte').bootstrapTable('removeByUniqueId', SampleDefinition_AnalyteId);  // 删除指定的行
                    SampleDefinition_AnalyteId = "";  // 删除行后，将这个值置空，否则直接编辑信息就会报错。
                } else {
                    alert(data);
                }
            });

            $("#SampleDefinition-DelAnalyteRelation-modal").modal('hide');
        });

        $("#SampleDefinition-AddSampleDefinition").click(function () {
            $("#modalTitle").text("添加样品定义");

            $("#SAMPLE-SampleDefinition-Modal").modal({
                backdrop: 'static',
                keyboard: false
            });

            $.post("AddSampleDefinition", {
                //Id:SampleDefinition_Id,
                ModalID: "SAMPLE-SampleDefinition-Modal"
            }, function (datas) {
                $("#Embed").html(datas);
            });
        });

        $("#SampleDefinition-EditSampleDefinition").click(function () {
            if (SampleDefinition_Id.length == 0) {
                alert("请先选择需要编辑的样品！");
                return;
            }

            $("#modalTitle").text("编辑样品");

            $("#SAMPLE-SampleDefinition-Modal").modal({
                backdrop: 'static',
                keyboard: false
            });

            $.post("AddSampleDefinition", {
                id: SampleDefinition_Id,
                ModalID: "SAMPLE-SampleDefinition-Modal"
            }, function (datas) {
                $("#Embed").html(datas);
            });
        });

        $('#SAMPLE-SampleDefinition-Modal').on('hidden.bs.modal', function (event) {
            if (event.target == this) {
                if (SampleDefinition_Id.length > 0) {

                    $.post("GetSampleDefinition", {
                        Id: SampleDefinition_Id
                    }, function (data) {
                        var row = $('#SampleDefinition-Table').bootstrapTable('getRowByUniqueId', SampleDefinition_Id);
                        row.name = data.name;
                        row.description = data.description;
                        row.site = data.site;
                        row.group = data.group;
                        row.reportName = data.reportName;
                        row.workFlowName = data.workFlowName;
                        row.samplingPoint = data.samplingPoint;
                        $('#SampleDefinition-Table').bootstrapTable('updateByUniqueId',row);
                        LoadAnalyte(SampleDefinition_Id);
                        LoadTestDefinition();
                        LoadSpecCollection(SampleDefinition_Id);

                        $("#SampleDefinition-Table").find("tbody").find("tr").each(function () {
                            if ($(this).attr("data-uniqueid") == SampleDefinition_Id)
                                $(this).addClass("changeblueColor");
                        });
                    });
                }
            }
        });

        $("#SampleDefinition-tabAnalyte-addAnalyte").click(function () {
            if (SampleDefinition_Id.length == 0) {
                alert("请先选择需要添加关系的样品！");
                return;
            }

            $("#modalTitle").text("添加关联分析项");

            $("#SAMPLE-SampleDefinition-Modal").modal({
                backdrop: 'static',
                keyboard: false
            });

            $.post("AddRelationSDAndAnalyte", {
                SampleDefinitonId: SampleDefinition_Id,
                ModalID: "SAMPLE-SampleDefinition-Modal"
            }, function (datas) {
                $("#Embed").html(datas);
            });
        });

        $("#SampleDefinition-tabAnalyte-delAnalyte").click(function () {
            if (SampleDefinition_AnalyteId.length == 0) {
                alert("请先选择需要删除关系的分析项！");
                return;
            }

            $("#modalTitle").text("删除关联分析项");

            $("#SampleDefinition-DelAnalyteRelation-modal").modal({
                backdrop: 'static',
                keyboard: false
            });
        });

        function SetRepeat(value, row, index) {
            var text = value == null ? '-' : value;
            var strHtml = "<input class='table-cell-input' data-Id=" + row.id + "  onchange='UpdateRepeat(this)' value='" + text + "' style='text-align: center;'/>";
            return strHtml;
        }

        function UpdateRepeat(obj) {
            var st = $(obj).val();
            $.post("postUpdateRelationRepeat", {
                Id: $(obj.outerHTML).attr("data-Id"),
                Repeat: st
            },  function (data) {
                if (data.indexOf("成功") <= 0) {
                    alert(data);
                }
            });
        }

        function InitSubTable(index, row, $detail) {
            var subtable = $detail.html('<table></table>').find('table');
            var columns = [{ field: "id", visible: false }, { field: "code", title: "代码" }, { field: "name", title: "名称" },
            { field: "classification", title: "分类" }, { field: "description", title: "描述" }, { field: "resultModel", title: "结果模式" },
            { field: "roundingOff", title: "修约" }, { field: "units", title: "单位" }, { field: "defaultSpecName", title: "默认指标" }, 
            { field: "assist", title: "报告过滤" },{ field: "detectionTimes", width: "5%", title: "检测次数" }];

            $(subtable).bootstrapTable({
                method: 'post',
                url: "GetTestDifinitonAnalytesByRelationId",
                dataType: "json",  // 服务器端返回值类型
                contentType: "application/x-www-form-urlencoded; charset=UTF-8", // 如果是 POST 请求，这个属性必须加
                queryParams: function (params) {
                    var data = {
                        RelationId: row.id
                    };
                    return data;
                },
                queryParamsType: "search",

                uniqueId: "id",
                locale: "zh-CN",
                columns: columns,
                onClickRow: function (row, $element, field) {
                    $(subtable).find("tbody").find("tr").each(function () {
                        $(this).removeClass('changeblueColor');
                    });
                    $element.addClass("changeblueColor");
                },
                silent: true,  //刷新事件必须设置

                formatLoadingMessage: function () {
                    return "请稍等，正在加载中...";
                },
                formatNoMatches: function () {  //没有匹配的结果
                    return '无符合条件的记录';
                },
                onLoadError: function (data) {
                    $(subtable).bootstrapTable('removeAll');
                },
                onLoadSuccess: function (data) {   // 数据加载成功后触发该事件
                    SetBootstrapStyle();
                }
            });
        }

        function LoadTestDefinition() {
            SampleDefinition_TestDefinitonId = "";  /*清空该值*/
            $('#SampleDefinition-tabTestDefinition-TD').bootstrapTable('destroy'); // 这行代码必须加，否则数据无法刷新
            var columns = [{ field: "id", visible: false }, { field: "testName", width: "10%", align: "center" },
            { field: "description", align: "left" },{ field: "firstGroup", align: "left" },
                { field: "secondGroup", align: "left" }, { field: "repeat", width: "5%", formatter: SetRepeat },
                { field: "version", width:"5%", align:"center" }];

            $('#SampleDefinition-tabTestDefinition-TD').bootstrapTable({
                method: 'post',
                url: "GetRelationTestDefinition",
                dataType: "json",  // 服务器端返回值类型
                contentType: "application/x-www-form-urlencoded; charset=UTF-8", // 如果是 POST 请求，这个属性必须加
                queryParams: function (params) {
                    var data = {
                        SampleDefinitonId: SampleDefinition_Id  // 传递的参数，这的名称要和控制器里对应的参数名称一样
                    };
                    return data;
                }, //参数
                queryParamsType: "search", //参数格式,发送标准的RESTFul类型的参数请求

                uniqueId: "id",          // 设置主键
                locale: "zh-CN",
                columns: columns,          // 加载列定义, 注意！这个地方绑定的列名称开头大写字母会全部变成小写。
                onClickRow: function (row, $element, field) {
                    $("#SampleDefinition-tabTestDefinition-TD").find("tbody").find("tr").each(function () {
                        $(this).removeClass('changeblueColor');
                    });
                    $element.addClass("changeblueColor");
                    SampleDefinition_TestDefinitonId = row.id;
                    LoadTestDefinitionAnalyte(SampleDefinition_TestDefinitonId);
                    LoadTestDefinitionMethod(row.includedId);
                    LoadTestDefinitionSpecCollection(row.includedId);
                },
                silent: true,  //刷新事件必须设置

                detailView: true,  // 详细视图必须设置该项
                icons:{  // 设置详细视图的图标
                    detailOpen: 'bi-plus',
                    detailClose: 'bi-dash'
                },
                onExpandRow: function (index, row, $detail) {  // 单击展开视图时触发的函数
                     InitSubTable(index, row, $detail);
                },

                formatLoadingMessage: function () {
                    return "请稍等，正在加载中...";
                },
                formatNoMatches: function () {  //没有匹配的结果
                    return '无符合条件的记录';
                },
                onLoadError: function (data) {
                    $('#SampleDefinition-tabTestDefinition-TD').bootstrapTable('removeAll');
                },
                onLoadSuccess: function (data) {   // 数据加载成功后触发该事件
                    SetBootstrapStyle();
                }
            });

            $('#SampleDefinition-tabTestDefinition-Analyte').bootstrapTable('removeAll');
        }

        function LoadTestDefinitionAnalyte(TestDefinitonId) {
            var columns = [{ field: "id", visible: false }, { field: "code" }, { field: "name" }, { field: "classification" }, { field: "description" },
            { field: "resultModel" }, { field: "roundingOff" }, { field: "units" }, { field: "defaultSpecName" }];

            $('#SampleDefinition-tabTestDefinition-Analyte').bootstrapTable('destroy'); // 这行代码必须加，否则数据无法刷新
            $('#SampleDefinition-tabTestDefinition-Analyte').bootstrapTable({
                method: 'post',
                url: "GetTestDefinitionRelationAnalytes",
                dataType: "json",  // 服务器端返回值类型
                contentType: "application/x-www-form-urlencoded; charset=UTF-8", // 如果是 POST 请求，这个属性必须加
                queryParams: function (params) {
                    var data = {
                        TestDefinitionId: TestDefinitonId,  // 传递的参数，这的名称要和控制器里对应的参数名称一样
                    };
                    return data;
                }, //参数
                queryParamsType: "search", //参数格式,发送标准的RESTFul类型的参数请求

                uniqueId: "id",          // 设置主键
                locale: "zh-CN",
                columns: columns,          // 加载列定义, 注意！这个地方绑定的列名称开头大写字母会全部变成小写。
                onClickRow: function (row, $element, field) {
                    $("#SampleDefinition-tabTestDefinition-Analyte").find("tbody").find("tr").each(function () {
                        $(this).removeClass('changeblueColor');
                    });
                    $element.addClass("changeblueColor");
                    TestDefinition_TestAnalyteId = row.id;
                },
                silent: true,  //刷新事件必须设置
                formatLoadingMessage: function () {
                    return "请稍等，正在加载中...";
                },
                formatNoMatches: function () {  //没有匹配的结果
                    return '无符合条件的记录';
                },
                onLoadError: function (data) {
                    $('#Analyte').bootstrapTable('removeAll');
                },
                onLoadSuccess: function (data) {   // 数据加载成功后触发该事件
                    SetBootstrapStyle();
                }
            });
        }

        function SetSampleSpecCollectionIsDefault(value, row, index) {
            var strHtml = "";
            if (row.repeat == 1) {
                strHtml = "<input type='checkbox' checked onclick='UpdateSampleSpecCollectionIsDefault(this)' data-rowid='" + row.id + "'/>";
            } else {
                strHtml = "<input type='checkbox' onclick='UpdateSampleSpecCollectionIsDefault(this)' data-rowid='" + row.id + "'/>";
            }

            return strHtml;
        }

        function UpdateSampleSpecCollectionIsDefault(obj) {
            var rowid = $(obj).attr("data-rowid");

            $.post("UpdateSampleSpecCollectionIsDefault", {
                Id: rowid,
            }, function (data) {
                if (data.indexOf("成功") >= 0) {
                    LoadSpecCollection(SampleDefinition_Id);
                } else {
                    alert(data);
                }
            });
        }

        function InitSampleSpecCollection(index, row, $detail) {
            var subtable = $detail.html('<table></table>').find('table');
            var columns = [{ field: "id", visible: false }, { field: "code", title:"代码" }, { field: "name", title:"名称" }, 
            { field: "classification", title:"分类" }, { field: "description", title:"描述" },{ field: "resultModel", title: "结果模式" },
            { field: "roundingOff", title: "修约" }, { field: "units", title: "单位" }, { field: "lowA", title: "-3σ" },
            { field: "lowB", title: "-2σ" }, { field: "standardValue", title: "Std" }, { field: "highB", title: "+2σ" }, { field: "highA", title: "+3σ" }, 
            { field: "acceptanceCriteria", title:"验收标准" }];
            
            $(subtable).bootstrapTable({
                method: 'post',
                url: "GetSpecCollectionAnalytesByRelationId",
                dataType: "json",  // 服务器端返回值类型
                contentType: "application/x-www-form-urlencoded; charset=UTF-8", // 如果是 POST 请求，这个属性必须加
                queryParams: function (params) {
                    var data = {
                        RelationId: row.id,  // 传递的参数，这的名称要和控制器里对应的参数名称一样
                    };
                    return data;
                }, //参数
                queryParamsType: "search", //参数格式,发送标准的RESTFul类型的参数请求

                uniqueId: "id",          // 设置主键
                locale: "zh-CN",
                columns: columns,          // 加载列定义, 注意！这个地方绑定的列名称开头大写字母会全部变成小写。
                onClickRow: function (row, $element, field) {
                    $(subtable).find("tbody").find("tr").each(function () {
                        $(this).removeClass('changeblueColor');
                    });
                    $element.addClass("changeblueColor");
                },
                silent: true,  //刷新事件必须设置
                formatLoadingMessage: function () {
                    return "请稍等，正在加载中...";
                },
                formatNoMatches: function () {  //没有匹配的结果
                    return '无符合条件的记录';
                },
                onLoadError: function (data) {
                    $(subtable).bootstrapTable('removeAll');
                },
                onLoadSuccess: function (data) {   // 数据加载成功后触发该事件
                    SetBootstrapStyle();
                },
                formatShowingRows: function (pageFrom, pageTo, totalRows) {
                    return "正在显示第" + pageFrom + "到第" + pageTo + "条记录，总共" + totalRows + "条记录 ";
                },
                formatRecordsPerPage: function (pageNumber) {
                    return " 每页显示" + pageNumber + '条记录';
                }
            });
        }

        function LoadSpecCollection(SampleDefinitionId) {
            SampleDefinition_SpecCollectionId = "";
            var columns = [{ field: "id", visible: false }, { field: "repeat", width: "5%", align: "center", formatter: SetSampleSpecCollectionIsDefault },
            { field: "code" }, { field: "name" }, { field: "description" },
            { field: "firstGroup" }, { field: "secondGroup" },{ field: "version" }, { field: "releaseStatus" }];

            $('#SampleDefinition-tabSpecList').bootstrapTable('destroy'); // 这行代码必须加，否则数据无法刷新
            $('#SampleDefinition-tabSpecList').bootstrapTable({
                method: 'post',
                url: "GetRelationSpecCollection",
                dataType: "json",  // 服务器端返回值类型
                contentType: "application/x-www-form-urlencoded; charset=UTF-8", // 如果是 POST 请求，这个属性必须加
                queryParams: function (params) {
                    var data = {
                        SampleDefinitonId: SampleDefinitionId,
                    };
                    return data;
                }, //参数
                queryParamsType: "search", //参数格式,发送标准的RESTFul类型的参数请求

                uniqueId: "id",          // 设置主键
                locale: "zh-CN",
                columns: columns,          // 加载列定义, 注意！这个地方绑定的列名称开头大写字母会全部变成小写。
                onClickRow: function (row, $element, field) {
                    $("#SampleDefinition-tabSpecList").find("tbody").find("tr").each(function () {
                        $(this).removeClass('changeblueColor');
                    });
                    $element.addClass("changeblueColor");
                    SampleDefinition_SpecCollectionId = row.id;
                },
                silent: true,  //刷新事件必须设置

                detailView: true,  // 详细视图必须设置该项
                icons:{  // 设置详细视图的图标
                    detailOpen: 'bi-plus',
                    detailClose: 'bi-dash'
                },
                onExpandRow: function (index, row, $detail) {  // 单击展开视图时触发的函数
                    InitSampleSpecCollection(index, row, $detail);
                },

                formatLoadingMessage: function () {
                    return "请稍等，正在加载中...";
                },
                formatNoMatches: function () {  //没有匹配的结果
                    return '无符合条件的记录';
                },
                onLoadError: function (data) {
                    $('#Analyte').bootstrapTable('removeAll');
                },
                onLoadSuccess: function (data) {   // 数据加载成功后触发该事件
                    SetBootstrapStyle();
                },
                formatShowingRows: function (pageFrom, pageTo, totalRows) {
                    return "正在显示第" + pageFrom + "到第" + pageTo + "条记录，总共" + totalRows + "条记录 ";
                },
                formatRecordsPerPage: function (pageNumber) {
                    return " 每页显示" + pageNumber + '条记录';
                }
            });
        }

        function SetSpecCollectionIsDefault(value, row, index) {
            var strHtml = "";
            if (row.isDefault) {
                strHtml = "<input type='checkbox' checked onclick='UpdateSpecCollectionIsDefault(this)' data-rowid='" + row.id + "'/>";
            } else {
                strHtml = "<input type='checkbox' onclick='UpdateSpecCollectionIsDefault(this)' data-rowid='" + row.id + "'/>";
            }
            return strHtml;
        }

        function UpdateSpecCollectionIsDefault(obj) {
            var rowid = $(obj).attr("data-rowid");

            $.post("SetSpecCollectionIsDefault", {
                Id: rowid
            }, function (data) {
                if (data.indexOf("成功") >= 0) {
                    // LoadSpecCollection(TestDefinition_TestDefinitionId);
                } else {
                    alert(data);
                }
            });
        }

        function LoadTestDefinitionSpecCollection(TestDefinitonId) {
            var columns = [{ field: "id", visible: false }, { field: "isDefault", width: "5%", align: "center", formatter: SetSpecCollectionIsDefault },
            { field: "code" }, { field: "name" }, { field: "description" },
            { field: "firstGroup" }, { field: "secondGroup" }, { field: "version" }, { field: "releaseStatus" }];

            $('#tableTestSpecCollection').bootstrapTable('destroy'); // 这行代码必须加，否则数据无法刷新
            $('#tableTestSpecCollection').bootstrapTable({
                method: 'post',
                url: "GetTestDefinitionRelationSpecCollection",
                dataType: "json",  // 服务器端返回值类型
                contentType: "application/x-www-form-urlencoded; charset=UTF-8", // 如果是 POST 请求，这个属性必须加
                queryParams: function (params) {
                    var data = {
                        TestDefinitionId: TestDefinitonId,  // 传递的参数，这的名称要和控制器里对应的参数名称一样
                    };
                    return data;
                }, //参数
                queryParamsType: "search", //参数格式,发送标准的RESTFul类型的参数请求

                uniqueId: "id",          // 设置主键
                locale: "zh-CN",
                columns: columns,          // 加载列定义, 注意！这个地方绑定的列名称开头大写字母会全部变成小写。
                onClickRow: function (row, $element, field) {
                    $("#tableTestSpecCollection").find("tbody").find("tr").each(function () {
                        $(this).removeClass('changeblueColor');
                    });
                    $element.addClass("changeblueColor");
                },
                silent: true,  //刷新事件必须设置

                detailView: true,  // 详细视图必须设置该项
                icons: {  // 设置详细视图的图标
                    detailOpen: 'bi-plus',
                    detailClose: 'bi-dash'
                },
                onExpandRow: function (index, row, $detail) {  // 单击展开视图时触发的函数
                    InitTestSpecCollection(index, row, $detail);
                },

                formatLoadingMessage: function () {
                    return "请稍等，正在加载中...";
                },
                formatNoMatches: function () {  //没有匹配的结果
                    return '无符合条件的记录';
                },
                onLoadError: function (data) {
                    $('#Analyte').bootstrapTable('removeAll');
                },
                onLoadSuccess: function (data) {   // 数据加载成功后触发该事件
                    SetBootstrapStyle();
                },
                formatShowingRows: function (pageFrom, pageTo, totalRows) {
                    return "正在显示第" + pageFrom + "到第" + pageTo + "条记录，总共" + totalRows + "条记录 ";
                },
                formatRecordsPerPage: function (pageNumber) {
                    return " 每页显示" + pageNumber + '条记录';
                }
            });
        }

        function InitTestSpecCollection(index, row, $detail) {
            var subtable = $detail.html('<table></table>').find('table');
            var columns = [{ field: "id", visible: false }, { field: "code", title: "代码" }, { field: "name", title: "名称" },
            { field: "classification", title: "分类" }, { field: "description", title: "描述" }, { field: "resultModel", title: "结果模式" },
            { field: "roundingOff", title: "修约" }, { field: "units", title: "单位" }, { field: "lowA", title: "-3σ" },
            { field: "lowB", title: "-2σ" }, { field: "standardValue", title: "Std" }, { field: "highB", title: "+2σ" }, { field: "highA", title: "+3σ" },
            { field: "acceptanceCriteria", title: "验收标准" }];

            $(subtable).bootstrapTable({
                method: 'post',
                url: "GetSpecCollectionAnalytesByTestRelationId",
                dataType: "json",  // 服务器端返回值类型
                contentType: "application/x-www-form-urlencoded; charset=UTF-8", // 如果是 POST 请求，这个属性必须加
                queryParams: function (params) {
                    var data = {
                        TestRelationId: row.id,
                    };
                    return data;
                }, //参数
                queryParamsType: "search", //参数格式,发送标准的RESTFul类型的参数请求

                uniqueId: "id",          // 设置主键
                locale: "zh-CN",
                columns: columns,          // 加载列定义, 注意！这个地方绑定的列名称开头大写字母会全部变成小写。
                onClickRow: function (row, $element, field) {
                    $(subtable).find("tbody").find("tr").each(function () {
                        $(this).removeClass('changeblueColor');
                    });
                    $element.addClass("changeblueColor");
                },
                silent: true,  //刷新事件必须设置
                formatLoadingMessage: function () {
                    return "请稍等，正在加载中...";
                },
                formatNoMatches: function () {  //没有匹配的结果
                    return '无符合条件的记录';
                },
                onLoadError: function (data) {
                    $(subtable).bootstrapTable('removeAll');
                },
                onLoadSuccess: function (data) {   // 数据加载成功后触发该事件
                    SetBootstrapStyle();
                },
                formatShowingRows: function (pageFrom, pageTo, totalRows) {
                    return "正在显示第" + pageFrom + "到第" + pageTo + "条记录，总共" + totalRows + "条记录 ";
                },
                formatRecordsPerPage: function (pageNumber) {
                    return " 每页显示" + pageNumber + '条记录';
                }
            });
        }

        function SetMethodIsDefault(value, row, index) {
            var strHtml = "";
            if (row.isDefault) {
                strHtml = "<input type='checkbox' checked onclick='UpdateMethodIsDefault(this)' data-rowid='" + row.id + "'/>";
            } else {
                strHtml = "<input type='checkbox' onclick='UpdateMethodIsDefault(this)' data-rowid='" + row.id + "'/>";
            }
            return strHtml;
        }

        function UpdateMethodIsDefault(obj) {
            var rowid = $(obj).attr("data-rowid");
            $.post("SetMethodIsDefault", {
                Id: rowid
            }, function (data) {
                if (data.indexOf("成功") >= 0) {
                    // LoadTestDefinitionMethod(TestDefinition_TestDefinitionId);
                } else {
                    alert(data);
                }
            });

        }

        function setEffectiveDate(value, row, index) {
            if (!row.effectiveDate) {
                return '';
            } else {
                return row.effectiveDate.split('T')[0];
            }
        }

        function setExpireDate(value, row, index) {
            if (!row.expireDate) {
                return '';
            } else {
                return row.expireDate.split('T')[0];
            }
        }

        function LoadTestDefinitionMethod(TestDefinitonId) {
            var columns = [{ field: "id", visible: false }, { field: "isDefault", width: "5%", align: "center", formatter: SetMethodIsDefault },
            { field: "code" }, { field: "name" }, { field: "type" }, { field: "description" },
            { field: "effectiveDate", formatter: setEffectiveDate }, { field: "expireDate", formatter: setExpireDate }, { field: "recordSheet" },
            { field: "version", width: "5%", }, { field: "status", width: "5%", }];

            $('#tableTestMethod').bootstrapTable('destroy'); // 这行代码必须加，否则数据无法刷新
            $('#tableTestMethod').bootstrapTable({
                method: 'post',
                url: "GetTestDefinitionRelationMethod",
                dataType: "json",  // 服务器端返回值类型
                contentType: "application/x-www-form-urlencoded; charset=UTF-8", // 如果是 POST 请求，这个属性必须加
                queryParams: function (params) {
                    var data = {
                        TestDefinitionId: TestDefinitonId,  // 传递的参数，这的名称要和控制器里对应的参数名称一样
                    };
                    return data;
                }, //参数
                queryParamsType: "search", //参数格式,发送标准的RESTFul类型的参数请求

                uniqueId: "id",          // 设置主键
                locale: "zh-CN",
                columns: columns,          // 加载列定义, 注意！这个地方绑定的列名称开头大写字母会全部变成小写。
                onClickRow: function (row, $element, field) {
                    $("#tableTestMethod").find("tbody").find("tr").each(function () {
                        $(this).removeClass('changeblueColor');
                    });
                    $element.addClass("changeblueColor");
                },
                silent: true,  //刷新事件必须设置
                formatLoadingMessage: function () {
                    return "请稍等，正在加载中...";
                },
                formatNoMatches: function () {  //没有匹配的结果
                    return '无符合条件的记录';
                },
                onLoadError: function (data) {
                    $('#tableTestMethod').bootstrapTable('removeAll');
                },
                onLoadSuccess: function (data) {   // 数据加载成功后触发该事件
                    SetBootstrapStyle();
                },
                formatShowingRows: function (pageFrom, pageTo, totalRows) {
                    return "正在显示第" + pageFrom + "到第" + pageTo + "条记录，总共" + totalRows + "条记录 ";
                },
                formatRecordsPerPage: function (pageNumber) {
                    return " 每页显示" + pageNumber + '条记录';
                }
            });
        }

        $("#SampleDefinition-tabTestDefinition-addTD").click(function () {
            if (SampleDefinition_Id.length == 0) {
                alert("请先选择需要添加关系的样品！");
                return;
            }

            $("#modalTitle").text("添加关联测试");

            $("#SAMPLE-SampleDefinition-Modal").modal({
                backdrop: 'static',
                keyboard: false
            });

            $.post("AddRelationSDAndTestDefinition", {
                SampleDefinitonId: SampleDefinition_Id,
                ModalID: "SAMPLE-SampleDefinition-Modal"
            }, function (datas) {
                $("#Embed").html(datas);
            });
        });

        $("#SampleDefinition-tabTestDefinition-delTD").click(function () {
            if (SampleDefinition_TestDefinitonId.length == 0) {
                alert("请先选择需要删除关系的测试！");
                return;
            }

            $("#modalTitle").text("删除关联测试项");

            $("#SampleDefinition-DelTestDefinitionRelation-modal").modal({
                backdrop: 'static',
                keyboard: false
            });
        });

        $("#SampleDefinition-DelTestDefinitionRelation-modal-delete").click(function () {
            $.post("DelteRelationSDAndTestDefinition", {
                RelationId: SampleDefinition_TestDefinitonId
            }, function (data) {
                if (data.indexOf("成功") >= 0) {
                    $('#SampleDefinition-tabTestDefinition-TD').bootstrapTable('removeByUniqueId', SampleDefinition_TestDefinitonId);
                    $('#tableTestSpecCollection').bootstrapTable('removeAll');
                    $('#tableTestMethod').bootstrapTable('removeAll');
                    SampleDefinition_TestDefinitonId = "";
                } else {
                    alert(data);
                }
            });

            $("#SampleDefinition-DelTestDefinitionRelation-modal").modal('hide');
        });

        $("#SampleDefinition-tabSpecCollection-addSpc").click(function () {
            if (SampleDefinition_Id.length == 0) {
                alert("请先选择需要添加关系的样品！");
                return;
            }

            $("#modalTitle").text("添加关联指标集");

            $("#SAMPLE-SampleDefinition-Modal").modal({
                backdrop: 'static',
                keyboard: false
            });

            $.post("AddSampleSpecCollection", {
                SampleDefinitionId: SampleDefinition_Id,
                ModalID: "SAMPLE-SampleDefinition-Modal"
            }, function (datas) {
                $("#Embed").html(datas);
            });
        });

        $("#SampleDefinition-tabSpecCollection-delSpc").click(function () {
            if (SampleDefinition_SpecCollectionId.length == 0) {
                alert("请先选择需要删除关系的指标集！");
                return;
            }

            $("#modalTitle").text("删除关联指标集");

            $("#SampleDefinition-DelSpecCollectionRelation-modal").modal({
                backdrop: 'static',
                keyboard: false
            });
        });

        $("#SampleDefinition-DelSpecCollectionRelation-modal-delete").click(function () {
            $.post("DelteRelationSpecCollection", {
                RelationId: SampleDefinition_SpecCollectionId
            }, function (data) {
                if (data.indexOf("成功") >= 0) {
                    LoadSpecCollection(SampleDefinition_Id);
                    SampleDefinition_SpecCollectionId = "";  // 删除行后，将这个值置空，否则直接编辑信息就会报错。
                } else {
                    alert(data);
                }
            });

            $("#SampleDefinition-DelSpecCollectionRelation-modal").modal('hide');
        });

        $("#SampleDefinition-Modal-RetentionConfig-confirm").click(function () {
            $.post("UpdateSampleDefenitionRetentionConfigId", {
                SampleDefefinitionId: SampleDefinition_Id,
                RetentionConfigId: $("#Modal-Select-SRetentionConfig").find("option:selected").val()
            }, function (data) {
                if (data.indexOf("成功") >= 0) {
                    $("#SampleDefinition-Modal-RetentionConfig").modal('hide');
                } else {
                    alert(data);
                }
            });
        });

        $(".tabButton").hover(
            function () {
                $('.tabButton').addClass('tab-first-mouse'); // 鼠标进入时绑定样式
            },
            function () {
                $('.tabButton').removeClass('tab-first-mouse'); // 鼠标进入时绑定样式
        });

        $("#li-tabAnalyte").hover(
            function () {
                if ($(this).attr("class").indexOf('tab-first-active') > 0) {
                    $(this).addClass('tab-enter-mouse');
                }
                if ($(this).attr("class").indexOf('tab-first-noactive') > 0) {
                    $(this).removeClass('tab-first-noactive');
                    $(this).addClass('tab-first-noactive-mouse');
                }
            },
            function () {
                $(this).removeClass('tab-enter-mouse');
                $(this).removeClass('tab-first-noactive-mouse');

                if ($(this).attr("data-active") == 'true') {
                    $(this).addClass('tab-first-active');
                }
                if ($(this).attr("data-active") == 'false') {
                    $(this).addClass('tab-first-noactive');
                }
            });

        $("#li-tabTestDefinition").hover(
            function () {
                if ($(this).attr("class").indexOf('tab-other-active') > 0) {
                    $(this).addClass('tab-enter-mouse');
                }
                if ($(this).attr("class").indexOf('tab-other-noactive') > 0) {
                    $(this).removeClass('tab-other-noactive');
                    $(this).addClass('tab-other-noactive-mouse');
                }
            },
            function () {
                $(this).removeClass('tab-enter-mouse');
                $(this).removeClass('tab-other-noactive-mouse');

                if ($(this).attr("data-active") == 'true') {
                    $(this).addClass('tab-other-active');
                }
                if ($(this).attr("data-active") == 'false') {
                    $(this).addClass('tab-other-noactive');
                }
            });

        $("#li-tabSpecCollection").hover(
            function () {
                if ($(this).attr("class").indexOf('tab-other-active') > 0) {
                    $(this).addClass('tab-enter-mouse');
                }
                if ($(this).attr("class").indexOf('tab-other-noactive') > 0) {
                    $(this).removeClass('tab-other-noactive');
                    $(this).addClass('tab-other-noactive-mouse');
                }
            },
            function () {
                $(this).removeClass('tab-enter-mouse');
                $(this).removeClass('tab-other-noactive-mouse');

                if ($(this).attr("data-active") == 'true') {
                    $(this).addClass('tab-other-active');
                }
                if ($(this).attr("data-active") == 'false') {
                    $(this).addClass('tab-other-noactive');
                }
            });

        $("#a-tabAnalyte").click(function () {
            if ($("#li-tabTestDefinition").attr("class").indexOf('tab-other-active') > 0) {
                $("#li-tabTestDefinition").removeClass('tab-other-active');
                $("#li-tabTestDefinition").addClass('tab-other-noactive');
            }
            if ($("#li-tabSpecCollection").attr("class").indexOf('tab-other-active') > 0) {
                $("#li-tabSpecCollection").removeClass('tab-other-active');
                $("#li-tabSpecCollection").addClass('tab-other-noactive');
            }

            $("#li-tabAnalyte").attr("data-active", true);
            $("#li-tabTestDefinition").attr("data-active", false);
            $("#li-tabSpecCollection").attr("data-active", false);
        });

        $("#a-tabTestDefinition").click(function () {
            if ($("#li-tabAnalyte").attr("class").indexOf('tab-first-active') > 0) {
                $("#li-tabAnalyte").removeClass('tab-first-active');
                $("#li-tabAnalyte").addClass('tab-first-noactive');
            }
            if ($("#li-tabSpecCollection").attr("class").indexOf('tab-other-active') > 0) {
                $("#li-tabSpecCollection").removeClass('tab-other-active');
                $("#li-tabSpecCollection").addClass('tab-other-noactive');
            }

            $("#li-tabTestDefinition").attr("data-active", true);
            $("#li-tabAnalyte").attr("data-active", false);
            $("#li-tabSpecCollection").attr("data-active", false);
        });

        $("#a-tabSpecCollection").click(function () {
            if ($("#li-tabAnalyte").attr("class").indexOf('tab-first-active') > 0) {
                $("#li-tabAnalyte").removeClass('tab-first-active');
                $("#li-tabAnalyte").addClass('tab-first-noactive');
            }
            if ($("#li-tabTestDefinition").attr("class").indexOf('tab-other-active') > 0) {
                $("#li-tabTestDefinition").removeClass('tab-other-active');
                $("#li-tabTestDefinition").addClass('tab-other-noactive');
            }

            $("#li-tabSpecCollection").attr("data-active", true);
            $("#li-tabAnalyte").attr("data-active", false);
            $("#li-tabTestDefinition").attr("data-active", false);
        });

        $("#a-tabTestMethod").click(function () {
            $("#li-tabTestSpecCollection").removeClass('tab-first-active');
            $("#li-tabTestSpecCollection").addClass('tab-first-noactive');

            $("#li-tabTestMethod").removeClass('tab-other-noactive');
            $("#li-tabTestMethod").addClass('tab-other-active');
        });

        $("#a-tabTestSpecCollection").click(function () {
            $("#li-tabTestMethod").removeClass('tab-other-active');
            $("#li-tabTestMethod").addClass('tab-other-noactive');

            $("#li-tabTestSpecCollection").removeClass('tab-first-noactive');
            $("#li-tabTestSpecCollection").addClass('tab-first-active');
        });


    </script>
}
